package com.jungle.service;

import com.jungle.base.utils.ReflectUtil;
import org.springframework.cglib.core.ClassInfo;

import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class ObjectType {

    public static boolean isByte(Class<?> clazz) {
        ClassInfo info;
        Type genericType = clazz.getGenericSuperclass();

        return true;
    }

    // Primitive types
    private byte aByte;
    private short aShort;
    private int aInt;
    private long aLong;
    private float aFloat;
    private double aDouble;
    private boolean aBoolean;
    private char aChar;

    // Boxed types
    private Byte bByte;
    private Short bShort;
    private Integer bInt;
    private Long bLong;
    private Float bFloat;
    private Double bDouble;
    private BigDecimal aBigDecimal;
    private BigInteger aBigInteger;

    private Boolean bBoolean;
    private Character bChar;

    // String
    private String aString;

    private String[] aryString;

    // Number
    private Number aNumber;

    private Collection<String> aCollection;

    // Date
    private Date aDate;


    public static void main(String[] args) {
        //test1();
        Object obj =  Integer.valueOf(1);
        int ii = 12;
        System.out.println(obj instanceof Number);
        System.out.println(Double.valueOf(2.5) instanceof Number);

        System.out.println(obj instanceof Number);

    }

    private static void test1() {
        ObjectType obj = new ObjectType();
        List<Field> fields = ReflectUtil.findAllField(ObjectType.class, new ArrayList<>());
        fields.forEach(field -> System.out.println(toString(field, obj)));
    }

    private static String toString(Field field, ObjectType obj) {
        Object value = ReflectUtil.getFieldValue(obj, field);
        Class<?> type = field.getType();
        boolean primitive = type.isPrimitive();
        boolean array = type.isArray();
        //boolean number = type.isAssignableFrom(Number.class);
        boolean instance = type.isInstance(Number.class);
        boolean number2 = type.isAssignableFrom(Number.class);
        String componentName = type.getComponentType() == null ? "" : type.getComponentType().getSimpleName();
        return String.format("%-10s\t%-10s\t%-10s\t%s\t%s\t%s\t%s", field.getName(), type.getSimpleName(), componentName, primitive, array, number2, instance);
    }

}
